package com.shujia.mr.kqzl1;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class KqzlReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        //<20180101-1001,[123,124,176,23,0,....]>
        long sum = 0L;
        int count = 0;
        for (LongWritable value : values) {
            sum+=value.get();
            count++;
        }

        //求平均值
        long pm25Avg = sum/count;
        context.write(key,new LongWritable(pm25Avg));

    }
}
